//
//  HNTimeBoxController.m
//  XDEducation
//
//  Created by 星道 on 17/5/27.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNTimeBoxController.h"

@interface HNTimeBoxController ()
@property (nonatomic, strong) NSMutableArray *DataArr;
@property (nonatomic, assign) NSInteger Index;
@end

@implementation HNTimeBoxController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.Index = 1;
    
    self.tableView.tableFooterView = [UIView new];
    self.tableView.tableHeaderView = [UIView new];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self RefreshData];
    }];
    [self.tableView.mj_footer beginRefreshing];
}




#pragma mark - 网络请求
- (void)RefreshData
{
    [MBProgressHUD showHUD];
    NSDictionary *Dict = @{
                           @"uid"       :[AccountTool shareAccountTool].currentAccount.uid,
                           @"funcCode"  :@5,
                           @"page"      :@(self.Index)
                           };
    [XDHttpTool get:BaseURL(@"user.do?action=getTimeMachine") authCode:[AccountTool shareAccountTool].currentAccount.authCode params:Dict success:^(id responseObj) {
        
        [self.tableView.mj_footer endRefreshing];
        if ([[responseObj allKeys] count] >3)
        {
            NSArray *Arr = responseObj[@"dataList"];
            if (Arr.count == 0)
            {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
            
            for (NSDictionary *Dict in Arr)
            {
                [self.DataArr addObject:Dict[@"context"]];
                self.Index += 1;
            }
            [self.tableView reloadData];
        }
        else
        {
            [MBProgressHUD showError:responseObj[@"data"][@"msg"]];
        }
    } failure:^(NSError *error) {
        
        [self.tableView.mj_footer endRefreshing];
        [MBProgressHUD showError:XDNetWorkError];
    }];
}


#pragma mark - TableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.DataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!Cell)
    {
        Cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"Cell"];
        Cell.textLabel.font = [UIFont systemFontOfSize:14.f];
        Cell.textLabel.textColor = UIColorFromRGB(0x4c4c4c);
        Cell.selectionStyle = UITableViewCellSelectionStyleNone;    }
    Cell.imageView.image = [UIImage imageNamed:@"list_icon_clock_default"];
    Cell.textLabel.text = self.DataArr[indexPath.row];
    return Cell;
}






#pragma mark - Setter
- (NSMutableArray *)DataArr
{
    if (!_DataArr)
    {
        _DataArr = [NSMutableArray array];
    }
    return _DataArr;
}
@end
